/**
 * 自定义函数
 * */


var formList = {
    data: [],
    pages: {start: 0, limit: 10}
}; //数据列表
var searchObj = {
    ucode: '', //用户标记
    code: '' //码值
}; //搜索条件
var searchObjOld = {
    ucode: '', //用户标记
    code: '' //码值
}; //搜索条件老的


//列表
function getIndex(){
    var reset = 0; //是否搜索重置
    if (formList.pages.start > 0 &&
        (searchObj.ucode != searchObjOld.ucode || searchObj.code != searchObjOld.code)) {
        formList.pages.start = 0;
        reset = 1;
    }
    if (searchObj.ucode != searchObjOld.ucode) {
        searchObjOld.ucode = searchObj.ucode;
    }
    if (searchObj.code != searchObjOld.code) {
        searchObjOld.code = searchObj.code;
    }
    console.log(reset);
    var formData = {
        aid: getAid(),
        ucode: searchObj.ucode,
        code: searchObj.code,
        pageStart: pages.start,
        pageLimit: pages.limit
    };
    console.log(formData);
    $.ajax({
        type: apis.qrLogIndex.method,
        url: apis.qrLogIndex.url,
        data: formData,
        success: function (res) {
            console.log(res);
            var h = '', tbody = $('tbody');
            if (res.code != 0) {
                h = '<tr class="text-c">';
                h += '<td colspan="10">没有记录</td>';
                h += '</tr>';
                tbody.html(h);
                return
            }
            tbody.html(getHtml(res.data));
            $('#pageTotal').html(res.total);
            pages.total = res.total;
            pageHtml(pages);
        },
        error: function () {
            console.log('网络错误');
        }
    });
}


//列表字符串
function getHtml(d){
    var h = '', i;
    h += '';
    for (i = 0; i < d.length; i ++) {
        h += '<tr class="text-c">';
        h += '<td>' + d[i].id + '</td>';
        h += '<td>' + d[i].uid + '</td>';
        h += '<td>' + d[i].code + '</td>';
        //h += '<td>' + d[i].view + '</td>';
        h += '<td>' + d[i].addtime + '</td>';
        h += '</tr>';
    }
    return h;
}